
"""
Created on Tue Feb 19 14:55:43 2013

@author: aponteeduarddo@gmail.com
Copyright Eduardo Aponte 2013.
"""

from mex_binder import binder_py

eyelink_read_reply = binder_py('mx_eyelink_read_reply')
eyelink_read_reply.mx_c.headers = ['<eyelink.h>','"mex.h"']
eyelink_read_reply.bindo += []
eyelink_read_reply.mx_c.code = \
"""
INT16 _main( char FARTYPE *msg )
{
    return eyelink_read_reply( msg );
}

void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] )
{
    mwSize td[] = {1,1};
    double *status;
    char FARTYPE *msg;

    /* Verify input arguments. */
    if(nrhs != 0 ) {
        mexErrMsgTxt("Incorrect number of inputs.");
    } else if( nlhs > 2 ) {
        mexErrMsgTxt("Too many output arguments.");
    }
             
    plhs[0] = mxCreateNumericArray( 2, td, mxDOUBLE_CLASS, mxREAL);
    status = mxGetPr(plhs[0]);
    *status = (double ) _main( msg );
    
    if ( nlhs == 2 ){
	if ( *status == 0 ){
	        plhs[1] = mxCreateString( msg );
		free( msg ); /* What is gonna happen ????) */
	} else {
		mwSize ts[] = {0};
		plhs[1] = mxCreateCellArray(0,ts);
	}
    }
    return;
}
"""

eyelink_read_reply.mx_c.mdoc = \
"""function [ status, buff] = mx_eyelink_read_reply( )
%MX_EYELINK_READ_REPLY Returns text with reply to last read request.
%
% Parameters:
% Returns:
% OK_RESULT (0) if response received.
% NO_REPLY (1000) if no response yet.
% buf 	String to contain text.
%
"""
eyelink_read_reply.write_c()
eyelink_read_reply.write_m()
eyelink_read_reply.compile()
eyelink_read_reply.write_sh()

